package algorithms.bloom;
import configuration.Configuration;
import simulator.Client;
import simulator.Manager;
import storage.Disk;
/**
* The manager that provides an access to the server
*
* @author Nodirjon Siddikov
*/
public class BloomManager extends Manager
{
private BloomClient[] _clients;
/**
* Constructor method for the bloom manager
*
* @param id ID of the manager
* @param disk The disk of the server
*/
public BloomManager(int id, Disk disk)
{
//call the constructor of the parent class
super(id, disk);
_clients = new BloomClient[Configuration.noOfClients];
}
/**
* The method that returns the list of clients
*
* @param clientID ID of the client that is not included in the list
* @return A list of clients
*/
public BloomClient[] getListOfClients(int clientID)
{
//create a list of clients
BloomClient[] _listOfClients = new BloomClient[Configuration.noOfClients - 1];
int index = 0;
for(BloomClient c: _clients)
{
if(c.getID() == clientID)
{
continue;
}
else
{
_listOfClients[index] = c;
index++;
}
}
return _listOfClients;
}
/**
* Sets the clients for the manager
*
* @param clients A list of clients
*/
public void setClients(Client[] clients)
{
//get the list of clients
for(int i = 0; i < clients.length; i++)
{
_clients[i] = (BloomClient)clients[i];
}
}
/**
* Gets the reference to the clients
*
* @param id ID of the client
* @return The reference to the client. Returns null if there is no client with such ID.
*/
public BloomClient getClient(int id)
{
for(BloomClient c: _clients)
{
if(c.getID() == id)
{
return c;
}
}
return null;
}
/**
* This method is used to calculate the size of the global cache.
*
* @return The size of the global cache
*/
public int getGlobalCacheSize()
{
int ttlGlobalCacheSize = 0;
for(BloomClient c: _clients)
{
ttlGlobalCacheSize += c.getClientCoopCacheSize();
}
return ttlGlobalCacheSize;
}
}